package com.mydistibute.distibutelearn.threadstatus;

import java.util.concurrent.TimeUnit;

/**
 * @author victorydeng
 * @Classname Demo
 * @Description TODO
 * @Date 2020/5/26 11:36
 * @Created by victorydeng
 */
public class Demo {

    public static void main(String[] args) {
        new Thread(()->{
            while(true){
                try {
                    TimeUnit.SECONDS.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"STATUS_01").start();  //阻塞状态

        new Thread(()->{
            while(true){
                synchronized (Demo.class){
                    try {
                        Demo.class.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        },"STATUS_02").start(); //阻塞状态

        new Thread(new BlockedDemo(),"BLOCKED-DEMO-01").start();
        new Thread(new BlockedDemo(),"BLOCKED-DEMO-02").start();

    }
    static class BlockedDemo extends  Thread{
        @Override
        public void run() {
            synchronized (BlockedDemo.class){
                while(true){
                    try {
                        TimeUnit.SECONDS.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}


/**
 * Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.191-b12 mixed mode):
 *
 * "DestroyJavaVM" #18 prio=5 os_prio=0 tid=0x0000000003504800 nid=0xc44 waiting on condition [0x0000000000000000]
 *    java.lang.Thread.State: RUNNABLE
 *
 * "BLOCKED-DEMO-02" #17 prio=5 os_prio=0 tid=0x000000001eeec800 nid=0x2ebc waiting for monitor entry [0x000000001f93f000]
 *    java.lang.Thread.State: BLOCKED (on object monitor)
 *         at com.mydistibute.distibutelearn.threadstatus.Demo$BlockedDemo.run(Demo.java:47)
 *         - waiting to lock <0x0000000774e21028> (a java.lang.Class for com.mydistibute.distibutelearn.threadstatus.Demo$BlockedDemo)
 *         at java.lang.Thread.run(Thread.java:748)
 *
 * "BLOCKED-DEMO-01" #15 prio=5 os_prio=0 tid=0x000000001eeec000 nid=0x28b4 waiting on condition [0x000000001f83e000]
 *    java.lang.Thread.State: TIMED_WAITING (sleeping)
 *         at java.lang.Thread.sleep(Native Method)
 *         at java.lang.Thread.sleep(Thread.java:340)
 *         at java.util.concurrent.TimeUnit.sleep(TimeUnit.java:386)
 *         at com.mydistibute.distibutelearn.threadstatus.Demo$BlockedDemo.run(Demo.java:47)
 *         - locked <0x0000000774e21028> (a java.lang.Class for com.mydistibute.distibutelearn.threadstatus.Demo$BlockedDemo)
 *         at java.lang.Thread.run(Thread.java:748)
 *
 * "STATUS_02" #13 prio=5 os_prio=0 tid=0x000000001eeeb000 nid=0x3e44 in Object.wait() [0x000000001f73e000]
 *    java.lang.Thread.State: WAITING (on object monitor)
 *         at java.lang.Object.wait(Native Method)
 *         - waiting on <0x00000007749f83d8> (a java.lang.Class for com.mydistibute.distibutelearn.threadstatus.Demo)
 *         at java.lang.Object.wait(Object.java:502)
 *         at com.mydistibute.distibutelearn.threadstatus.Demo.lambda$main$1(Demo.java:29)
 *         - locked <0x00000007749f83d8> (a java.lang.Class for com.mydistibute.distibutelearn.threadstatus.Demo)
 *         at com.mydistibute.distibutelearn.threadstatus.Demo$$Lambda$2/1996181658.run(Unknown Source)
 *         at java.lang.Thread.run(Thread.java:748)
 *
 * "STATUS_01" #12 prio=5 os_prio=0 tid=0x000000001eee6800 nid=0x3154 waiting on condition [0x000000001f63e000]
 *    java.lang.Thread.State: TIMED_WAITING (sleeping)
 *         at java.lang.Thread.sleep(Native Method)
 *         at java.lang.Thread.sleep(Thread.java:340)
 *         at java.util.concurrent.TimeUnit.sleep(TimeUnit.java:386)
 *         at com.mydistibute.distibutelearn.threadstatus.Demo.lambda$main$0(Demo.java:18)
 *         at com.mydistibute.distibutelearn.threadstatus.Demo$$Lambda$1/1896277646.run(Unknown Source)
 *         at java.lang.Thread.run(Thread.java:748)
 *
 * "Service Thread" #11 daemon prio=9 os_prio=0 tid=0x000000001e14c000 nid=0xbec runnable [0x0000000000000000]
 *    java.lang.Thread.State: RUNNABLE
 *
 * "C1 CompilerThread3" #10 daemon prio=9 os_prio=2 tid=0x000000001e06c800 nid=0x3bb8 waiting on condition [0x0000000000000000]
 *    java.lang.Thread.State: RUNNABLE
 *
 * "C2 CompilerThread2" #9 daemon prio=9 os_prio=2 tid=0x000000001e06c000 nid=0x29c0 waiting on condition [0x0000000000000000]
 *    java.lang.Thread.State: RUNNABLE
 *
 * "C2 CompilerThread1" #8 daemon prio=9 os_prio=2 tid=0x000000001e06b000 nid=0x1fb0 waiting on condition [0x0000000000000000]
 *    java.lang.Thread.State: RUNNABLE
 *
 * "C2 CompilerThread0" #7 daemon prio=9 os_prio=2 tid=0x000000001e06a800 nid=0x261c waiting on condition [0x0000000000000000]
 *    java.lang.Thread.State: RUNNABLE
 *
 * "Monitor Ctrl-Break" #6 daemon prio=5 os_prio=0 tid=0x000000001e082000 nid=0x2630 runnable [0x000000001e73e000]
 *    java.lang.Thread.State: RUNNABLE
 *         at java.net.SocketInputStream.socketRead0(Native Method)
 *         at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
 *         at java.net.SocketInputStream.read(SocketInputStream.java:171)
 *         at java.net.SocketInputStream.read(SocketInputStream.java:141)
 *         at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
 *         at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
 *         at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
 *         - locked <0x0000000774a87e00> (a java.io.InputStreamReader)
 *         at java.io.InputStreamReader.read(InputStreamReader.java:184)
 *         at java.io.BufferedReader.fill(BufferedReader.java:161)
 *         at java.io.BufferedReader.readLine(BufferedReader.java:324)
 *         - locked <0x0000000774a87e00> (a java.io.InputStreamReader)
 *         at java.io.BufferedReader.readLine(BufferedReader.java:389)
 *         at com.intellij.rt.execution.application.AppMainV2$1.run(AppMainV2.java:64)
 *
 * "Attach Listener" #5 daemon prio=5 os_prio=2 tid=0x000000001de72800 nid=0x35f4 waiting on condition [0x0000000000000000]
 *    java.lang.Thread.State: RUNNABLE
 *
 * "Signal Dispatcher" #4 daemon prio=9 os_prio=2 tid=0x000000001de1d800 nid=0x2844 runnable [0x0000000000000000]
 *    java.lang.Thread.State: RUNNABLE
 *
 * "Finalizer" #3 daemon prio=8 os_prio=1 tid=0x000000001de00800 nid=0x3fc8 in Object.wait() [0x000000001e3df000]
 *    java.lang.Thread.State: WAITING (on object monitor)
 *         at java.lang.Object.wait(Native Method)
 *         - waiting on <0x0000000774808ed0> (a java.lang.ref.ReferenceQueue$Lock)
 *         at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
 *         - locked <0x0000000774808ed0> (a java.lang.ref.ReferenceQueue$Lock)
 *         at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:165)
 *         at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:216)
 *
 * "Reference Handler" #2 daemon prio=10 os_prio=2 tid=0x000000001bfed800 nid=0x1c34 in Object.wait() [0x000000001e2df000]
 *    java.lang.Thread.State: WAITING (on object monitor)
 *         at java.lang.Object.wait(Native Method)
 *         - waiting on <0x0000000774806bf8> (a java.lang.ref.Reference$Lock)
 *         at java.lang.Object.wait(Object.java:502)
 *         at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
 *         - locked <0x0000000774806bf8> (a java.lang.ref.Reference$Lock)
 *         at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)
 *
 * "VM Thread" os_prio=2 tid=0x000000001bfe9000 nid=0x3cbc runnable
 *
 * "GC task thread#0 (ParallelGC)" os_prio=0 tid=0x000000000351a800 nid=0x382c runnable
 *
 * "GC task thread#1 (ParallelGC)" os_prio=0 tid=0x000000000351c000 nid=0x3da4 runnable
 *
 * "GC task thread#2 (ParallelGC)" os_prio=0 tid=0x000000000351d800 nid=0x11a8 runnable
 *
 * "GC task thread#3 (ParallelGC)" os_prio=0 tid=0x000000000351f000 nid=0x3f4c runnable
 *
 * "GC task thread#4 (ParallelGC)" os_prio=0 tid=0x0000000003521000 nid=0x2734 runnable
 *
 * "GC task thread#5 (ParallelGC)" os_prio=0 tid=0x0000000003523800 nid=0x38e4 runnable
 *
 * "GC task thread#6 (ParallelGC)" os_prio=0 tid=0x0000000003526800 nid=0x3a88 runnable
 *
 * "GC task thread#7 (ParallelGC)" os_prio=0 tid=0x0000000003527800 nid=0x370 runnable
 *
 * "VM Periodic Task Thread" os_prio=2 tid=0x000000001e179000 nid=0x100c waiting on condition
 *
 * JNI global references: 317
 */

